package it.softphone.cmc.server.rest;

import it.softphone.cmc.event.service.EventManagerService;
import it.softphone.cmc.server.service.exception.CMCException;
import it.softphone.commons.spring.ApplicationConfig;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;


@Path("/events")
public class CMCEventManager  {

	
	@GET 
    @Produces( "text/plain")
    @Path("token")
	public String createTokenRequest() throws CMCException {
		
		
		final EventManagerService service = ApplicationConfig.getBean(EventManagerService.class);
		String token =  service.createToken();
				
		return token;
	}

	@GET 
    @Produces("text/plain")
    @Path("send")
	public Response sendEventRequest(  @QueryParam("event")String event,  @QueryParam("toUser") String toUser ) throws CMCException  {

		final EventManagerService service = ApplicationConfig.getBean(EventManagerService.class);
		
		 service.sendEvent(event, toUser);
				 
	     return Response.ok().build();
	}    
}
